package com.gzz.demo.pattern.state;
/**
 * 定义当前的状态
 * @author gh
 *
 */
public class StateContext {
    private State state;

    public StateContext(State state) { //定义Context的初始状态
        super();
        this.state = state;
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
        System.out.println("当前状态为"+state);
    }
    public void requestProcess(){
        state.Handle(this); //对请求做处理并且指向下一个状态
    }

    public static void main(String[] args) {
        StateContext context = new StateContext(new StateA());
        // 不断请求，切换状态
        context.requestProcess();
        context.requestProcess();
        context.requestProcess();
        context.requestProcess();

    }
}
